SmitearWebGL.Objects.Parser.Collada.DaeAddressSyntax = Class.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.targetID = "";
		this.targetSID = "";
		this.member = "";
		this.isArrayAccess = false;
		this.isDotAccess = false;
		this.isFullAccess = false;
		this.arrayIndex0 = -1;
		this.arrayIndex1 = -1;
		
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeAddressSyntax" );
	}
	,
	toString : function()
	{
		return "\ntarget: " + this.targetID +
		"\nsid: " + this.targetSID +
		"\nmember: " + this.member +
		"\narrayIndex0: " + this.arrayIndex0 +
		"\narrayIndex1: " + this.arrayIndex1;
	}
}
);

SmitearWebGL.Objects.Parser.Collada.DaeAddressSyntax.parse = function( target )
{
	var syntax = new SmitearWebGL.Objects.Parser.Collada.DaeAddressSyntax();

	var pattern = /\((\d+)\)\((\d+)\)/;
	var matches = target.match(pattern);
	if( !matches )
	{
		pattern = /\((\d+)\)/;
		matches = target.match(pattern);
	}

	if(matches)
	{
		// array access
		target = target.replace(pattern, "");
		syntax.isArrayAccess = true;
		syntax.arrayIndex0 = parseInt(matches[1], 10);
		if(matches.length > 2)
		{
			syntax.arrayIndex1 = parseInt(matches[2], 10);
		}
	}
	else
	{
		var pos = target.lastIndexOf(".");
		if(pos != -1)
		{
			// dot access
			syntax.member = target.substr(pos+1);
			syntax.isDotAccess = true;
			target = target.substr(0, pos);
		}
		else
		{
			syntax.isFullAccess = true;
		}
	}

	if(target.indexOf("/") != -1)
	{
		var parts = target.split("/");

		syntax.targetID = parts.shift();
		syntax.targetSID = parts.join("/");
	}
	else
	{
		syntax.targetID = target;
	}

	return syntax;
}